import java.awt.Polygon;


public class Asteroid implements GameObject {

	private float posX;
	private float posY;
	private int angle;
	private boolean life;
	private float speed;	//speed per frame
	private Polygon shape;
	//asteroid speed
	
	private int AsRadius=0;
	
	
	//There a 2 types: 3, 2, 1
	//3 = large
	//2= medium
	//1= small
	private int TYPE;
	
	public int getType(){
		return TYPE;
	}
	public int getRad(){
		return AsRadius;
	}
	//new asteroid position, type, and default speed
	public Asteroid(int x,int y,int TYPE,float speed, int angle){
		posX= x;
		posY = y;
		this.TYPE=TYPE;
		createShape();
		this.speed=speed;
		this.angle= angle;
		
	}
	
	//update position, also angle
	public void update(){
	//	System.out.println("Updating...");
		//recount deltaX
		float radians = (float) Math.toRadians(angle);
		double deltaX= (speed)*Math.cos(radians); 
		double deltaY =(speed)*Math.sin(radians) ;	
		
		
		posX+=deltaX;
		if(posX> SpaceWar.ScreenWidth) posX=0;
		if(posX<0) posX=SpaceWar.ScreenWidth;
		
		posY+=deltaY;
		if(posY>SpaceWar.ScreenHeight) posY=0;
		if(posY<0) posY=SpaceWar.ScreenHeight;
		
		//angle++;
		if(angle==360) angle =0;
		//createShape();
		
		
	}
	@Override
	public int getPosX() {
		// TODO Auto-generated method stub
		return (int) posX;
	}

	@Override
	public void setPosX(int posX) {
		// TODO Auto-generated method stub
		this.posX=posX;
	}

	@Override
	public int getPosY() {
		// TODO Auto-generated method stub
		return (int) posY;
	}

	@Override
	public void setPosY(int posY) {
		// TODO Auto-generated method stub
		this.posY=posY;
	}

	@Override
	public float getSpeed() {
		// TODO Auto-generated method stub
		return speed;
	}

	@Override
	public void setSpeed(float speed) {
		// TODO Auto-generated method stub
		this.speed=speed;
	}

	@Override
	public int getAngle() {
		// TODO Auto-generated method stub
		return angle;
	}

	@Override
	public void setAngle(int angle) {
		// TODO Auto-generated method stub
		this.angle=angle;
	}

	@Override
	public void setLife(boolean life) {
		// TODO Auto-generated method stub
		this.life=life ;
	}

	@Override
	public boolean getLife() {
		// TODO Auto-generated method stub
		return life;
	}

	@Override
	public void setShape(Polygon shape) {
		// TODO Auto-generated method stub
		this.shape=shape;
	}

	@Override
	public Polygon getShape() {
		// TODO Auto-generated method stub
		Polygon s = new Polygon();
		for(int i=0;i<shape.npoints;i++){
			s.addPoint((int)(posX + shape.xpoints[i]), (int) (posY + shape.ypoints[i]));
		}
		return s;
	}

	@Override
	public void createShape() {
		// TODO Auto-generated method stub
		
		shape = new Polygon();
		
		switch (TYPE) {
		case 1:
			AsRadius=4;
			break;
		case 2:
			AsRadius=15;
			break;
		case 3:
			AsRadius=30;
			break;	
		}
		
		int s=15;
		for (int j = 0; j < s; j ++) {
			double theta = 2 * Math.PI / s * j;
	        int r = AsRadius + (int) (Math.random() * 10);
	        int x = (int) -Math.round(r * Math.sin(theta));
	        int y = (int)  Math.round(r * Math.cos(theta));
	        shape.addPoint(x, y);
	      }
		
	}

}
